home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / tsr_c.exe / VECTORS.C < prev    next >
C/C++ Source or Header  |  1992-03-24  |  4KB  |  168 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <dos.h>
  4. #include "vectors.h"
  5.  
  6. void interrupt (*old_8) (void);
  7. void interrupt (*old_23) (void);
  8. void interrupt (*old_24) (void);
  9. void interrupt (*old_28) (void);
  10. void interrupt (*old_2F) (void);
  11.  
  12. BYTE _8_chk_dos      =  1;           // check for DOS busy in the 8 handler?
  13. WORD _8_count        =  0;
  14. WORD _8_flag         =  0;
  15. WORD _8_max          = 18;
  16. WORD _8_stack[STACKSIZE] = {0};
  17. WORD _8_ss;
  18. WORD _8_sp;
  19. WORD want_in          = 0;
  20. WORD _28_flag         = 0;
  21.  
  22. WORD far *indos;
  23. WORD old_psp;
  24.  
  25. void enter_tsr (int x)
  26. {
  27.   if (_8_chk_dos)
  28.   {
  29.     _AH = 0x62;                    // get current PSP
  30.     geninterrupt (0x21);
  31.  
  32.     old_psp = _BX;                 // save it
  33.  
  34.     _AH = 0x50;                    // UNDOC DOS Set PSP to ours
  35.     _BX = _psp;
  36.     geninterrupt (0x21);
  37.  
  38.     old_23 = getvect (0x23);       // CTRL-Break handler
  39.     setvect (0x23, new_23);
  40.  
  41.     old_24 = getvect (0x24);       // critical error handler
  42.     setvect (0x24, new_24);
  43.   }
  44.  
  45.   tsr (x);
  46.  
  47.   if (_8_chk_dos)
  48.   {
  49.     setvect (0x24, old_24);        // reset them
  50.     setvect (0x23, old_23);
  51.  
  52.     _AH = 0x50;
  53.     _BX = old_psp;
  54.     geninterrupt (0x21);           // set the old psp back
  55.   }
  56. }
  57.  
  58. void interrupt new_8 ()
  59. {
  60.  
  61.   old_8 ();                        // call old vector
  62.  
  63.   if (++_8_count >= _8_max)
  64.   {
  65.     want_in = 1;
  66.     _8_count = 0;
  67.     if (!_8_flag)
  68.     {
  69.       if (DOSOK () || (!_8_chk_dos))
  70.       {
  71.         want_in = 0;
  72.         _8_flag = 1;
  73.         BEGINSTACK (_8_);             // switch to our stack
  74.         enter_tsr (8);
  75.         ENDSTACK (_8_);               // switch from our stack
  76.         _8_flag = 0;
  77.       }
  78.     }
  79.   }
  80. }
  81.  
  82. void interrupt new_28 (void)
  83. {
  84.   if (want_in == 1)
  85.   {
  86.     if (!_8_flag)
  87.     {
  88.       if (DOS28OK () || (!_8_chk_dos))
  89.       {
  90.         want_in = 0;
  91.         _8_flag = 1;
  92.         BEGINSTACK (_8_);             // switch to our stack
  93.         enter_tsr (0x28);
  94.         ENDSTACK (_8_);               // switch from our stack
  95.         _8_flag = 0;
  96.       }
  97.     }
  98.   }
  99.   else
  100.     chain (old_28);
  101. }
  102.  
  103. #pragma argsused
  104. void interrupt new_2F (bp,di,si,ds,es,dx,cx,bx,ax,ip,cs,flags)
  105. {
  106.   if (_AH == MY_ID)                 // for me
  107.   {
  108.     // if successful, AX = -1, BX = our PSP, and DX = our data segment
  109.  
  110.     switch (_AL)
  111.     {
  112.       case DETECT_CMD:
  113.            ax = 0xFFFF;
  114.            bx = _psp;
  115.            dx = _DS;
  116.            break;
  117.  
  118.       case UNLOAD_CMD:
  119.            // if vect's can be unloaded then they are, else
  120.            // the first offending vect is returned in CX
  121.  
  122.            if (FP_SEG(getvect (0x28)) == FP_SEG(new_28))
  123.            {
  124.              if (FP_SEG(getvect (0x08)) == FP_SEG(new_8))
  125.              {
  126.                if (FP_SEG(getvect (0x2F)) == FP_SEG(new_2F))
  127.                {
  128.                  ax = 0xFFFF;
  129.                  bx = _psp;
  130.                  dx = _DS;
  131.                  setvect (0x08, old_8);
  132.                  setvect (0x2F, old_2F);
  133.                  setvect (0x28, old_28);
  134.                }
  135.                else
  136.                  cx = 0x2F;
  137.              }
  138.              else
  139.                cx = 8;
  140.            }
  141.            else
  142.              cx = 0x28;
  143.            break;
  144.  
  145.       default:
  146.            chain (old_2F);
  147.     }
  148.     return;
  149.   }
  150.   else
  151.   if (_AX == 0x7A85)             // novell broadcast msg
  152.   {
  153.   }
  154.   chain (old_2F);
  155. }
  156.  
  157. void interrupt new_23 (void)
  158. {
  159.   // do nothing
  160. }
  161.  
  162. #pragma argsused
  163. void interrupt new_24 (bp,di,si,ds,es,dx,cx,bx,ax,ip,cs,flags)
  164. {
  165.   ax = 3;          // fail the function
  166. }
  167.  
  168.